@extends('layouts.app')

@section('head-js')
<script src="{{ asset('a/plugins/jQuery/jquery-2.2.3.min.js') }}"></script>
<script type="text/javascript">
  $(document).ready(function(){getJSONData();});
  function getJSONData()
  {
    setTimeout('getJSONData()', 1000);
    $.getJSON('/api_admin/getJson', displayData);
  }
  function displayData(dataJSON)
  {
    $('#stime').html(dataJSON.stime);
    $('#uptime').html(dataJSON.uptime);
    $('#memPercent').html(dataJSON.memPercent);
  }
</script>
@endsection

@section('content')
<section class="content">
  <!-- Info boxes -->
  <div class="row">
    <div class="col-md-3 col-sm-6 col-xs-12">
      <div class="info-box">
        <span class="info-box-icon bg-yellow"><i class="ion ion-ios-people-outline"></i></span>

        <div class="info-box-content">
          <span class="info-box-text">用户</span>
          <span class="info-box-number">{{ $userCount }}</span>
        </div>
        <!-- /.info-box-content -->
      </div>
      <!-- /.info-box -->
    </div>
    <!-- /.col -->

    <!-- fix for small devices only -->
    <div class="clearfix visible-sm-block"></div>

    <div class="col-md-3 col-sm-6 col-xs-12">
      <div class="info-box">
        <span class="info-box-icon bg-aqua"><i class="ion ion-ios-calendar"></i></span>

        <div class="info-box-content">
          <span class="info-box-text">活动</span>
          <span class="info-box-number">{{ $activityCount }}</span>
        </div>
        <!-- /.info-box-content -->
      </div>
      <!-- /.info-box -->
    </div>

    <!-- fix for small devices only -->
    <div class="clearfix visible-sm-block"></div>

    <div class="col-md-3 col-sm-6 col-xs-12">
      <div class="info-box">
        <span class="info-box-icon bg-green"><i class="ion ion-share"></i></span>

        <div class="info-box-content">
          <span class="info-box-text">分享</span>
          <span class="info-box-number">{{ $tweetCount }}</span>
        </div>
        <!-- /.info-box-content -->
      </div>
      <!-- /.info-box -->
    </div>

    <!-- fix for small devices only -->
    <div class="clearfix visible-sm-block"></div>

    <div class="col-md-3 col-sm-6 col-xs-12">
      <div class="info-box">
        <span class="info-box-icon bg-red"><i class="ion ion-chatbubbles"></i></span>

        <div class="info-box-content">
          <span class="info-box-text">反馈</span>
          <span class="info-box-number">{{ $feedbackCount }}</span>
        </div>
        <!-- /.info-box-content -->
      </div>
      <!-- /.info-box -->
    </div>
  </div>

  <div class="row">
    <div class="col-md-12">
      <div class="box">
        <div class="box-header with-border">
          <h3 class="box-title">服务器实时数据(图表)</h3>
        </div>
        <div class="box-body no-padding">
          <table class="table table-bordered">
            <tr>
              <th style="width: 10px">#</th>
              <th style="width: 120px">名称</th>
              <th>进度</th>
              <td style="width: 100px">共</td>
              <td style="width: 100px">已用</td>
              <td style="width: 100px">空闲</td>
              <th style="width: 60px">百分比</th>
            </tr>
            <tr>
              <td>1.</td>
              <td>物理内存</td>
              <td>
                <div class="progress progress-xs progress-striped active">
                  <div class="progress-bar progress-bar-success" style="width: {{ $memPercent.'%' }}"></div>
                </div>
              </td>
              <td>{{ $memTotal }}</td>
              <td>{{ $mu }}</td>
              <td>{{ $mf }}</td>
              <td><span id="memPercent" class="badge bg-green">{{ $memPercent.'%' }}</span></td>
            </tr>
          </table>
        </div>
      </div>
      <!-- /.box -->
    </div>
    <div class="col-md-6">
      <div class="box">
        <div class="box-header with-border">
          <h3 class="box-title">服务器参数</h3>
        </div>
        <!-- /.box-header -->
        <div class="box-body no-padding">
          <table class="table table-bordered">
            <tr>
              <th style="width: 10px">#</th>
              <th>名称</th>
              <th>值</th>
            </tr>
            <tr>
              <td>1.</td>
              <td>服务器域名/IP地址</td>
              <td>
                <?php echo $_SERVER['SERVER_NAME'];?>
                (<?php 
                  if('/'==DIRECTORY_SEPARATOR){
                    echo $_SERVER['SERVER_ADDR'];
                  }else{
                    echo @gethostbyname($_SERVER['SERVER_NAME']);
                  } 
                ?>)
              </td>
            </tr>
            <tr>
              <td>2.</td>
              <td>服务器操作系统</td>
              <td>
                <?php 
                  $os = explode(" ", php_uname()); 
                  echo $os[0];
                ?> 
                &nbsp;内核版本：
                <?php 
                  if('/'==DIRECTORY_SEPARATOR){
                    echo $os[2];
                  }else{
                    echo $os[1];
                  } 
                ?>
              </td>
            </tr>
            <tr>
              <td>3.</td>
              <td>服务器解译引擎</td>
              <td>
                <?php echo $_SERVER['SERVER_SOFTWARE'];?>
              </td>
            </tr>
            <tr>
              <td>4.</td>
              <td>服务器语言</td>
              <td>
                <?php echo getenv("HTTP_ACCEPT_LANGUAGE");?>
              </td>
            </tr>
            <tr>
              <td>5.</td>
              <td>服务器端口</td>
              <td>
                <?php echo $_SERVER['SERVER_PORT'];?>
              </td>
            </tr>
            <tr>
              <td>6.</td>
              <td>服务器主机名</td>
              <td>
                <?php if('/'==DIRECTORY_SEPARATOR ){echo $os[1];}else{echo $os[2];} ?>
              </td>
            </tr>
            <tr>
              <td>7.</td>
              <td>绝对路径</td>
              <td>
                <?php 
                  echo $_SERVER['DOCUMENT_ROOT']?str_replace('\\','/',$_SERVER['DOCUMENT_ROOT']):str_replace('\\','/',dirname(__FILE__));
                ?>
              </td>
            </tr>
            <tr>
              <td>8.</td>
              <td>服务器标识</td>
              <td>
                <?php echo @php_uname();?>
              </td>
            </tr>
          </table>
        </div>
        <!-- /.box-body -->
      </div>
    </div>
    <div class="col-md-6">
      <div class="box">
        <div class="box-header">
          <h3 class="box-title">服务器实时数据</h3>
        </div>
        <!-- /.box-header -->
        <div class="box-body no-padding">
          <table class="table table-bordered">
            <tr>
              <th style="width: 10px">#</th>
              <th>名称</th>
              <th>值</th>
            </tr>
            <tr>
              <td>1.</td>
              <td>服务器当前时间</td>
              <td>
                <span id="stime">{{ $stime }}</span>
              </td>
            </tr>
            <tr>
              <td>2.</td>
              <td>服务器已运行时间</td>
              <td>
                <span id="uptime">{{ $uptime }}</span>
              </td>
            </tr>
            <tr>
              <td>3.</td>
              <td>总空间</td>
              <td>
                <?php echo $dt;?>&nbsp;GB
              </td>
            </tr>
            <tr>
              <td>4.</td>
              <td>可用空间</td>
              <td>
                <span class="text-red"><?php echo $df;?></span>&nbsp;GB
              </td>
            </tr>
          </table>
        </div>
        <!-- /.box-body -->
      </div>

      <div class="box">
        <div class="box-header">
          <h3 class="box-title">网络使用状况</h3>
        </div>
        <div class="box-body no-padding">
        <?php if (false !== ($strs = @file("/proc/net/dev"))) : ?>
        <table class="table table-bordered">
          <tr>
            <th>#</th>
            <th>已接收</th>
            <th>已发送</th>
          </tr>
          <?php for ($i = 2; $i < count($strs); $i++ ) : ?>
          <?php preg_match_all( "/([^\s]+):[\s]{0,}(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/", $strs[$i], $info );?>
            <tr>
              <td width="13%">
                <?php echo $info[1][0]?> : 
              </td>
              <td width="43%">
                <span class="text-red" id="NetInput<?php echo $i?>">
                  <?php echo $NetInput[$i]?>
                </span> GB
              </td>
              <td width="43%">
                <span class="text-red" id="NetOut<?php echo $i?>">
                  <?php echo $NetOut[$i]?>
                </span> GB
              </td>
            </tr>
          <?php endfor; ?>
        </table>
        <?php endif; ?>
        </div>
      </div>
    </div>
  </div>
  <!-- /.row -->
</section>

@endsection

